/**
 *
 */
package commons.beancopier.internal;


import org.apache.commons.beanutils.BeanUtils;
import org.apache.commons.beanutils.PropertyUtils;

import com.tmall.common.beancopier.AbstractPropertyCopier;
import com.tmall.common.beancopier.BeanCopier;
import com.tmall.common.beancopier.mapper.PropertiesMapperBuilder;

/**
 * @author 陌铭(Phenix Huang)
 *
 */
public class BasicPropertyCopier extends AbstractPropertyCopier {



    public BasicPropertyCopier() {
        super();
        // TODO Auto-generated constructor stub
    }

    public BasicPropertyCopier(PropertiesMapperBuilder mapper, BeanCopier copier) {
        super(mapper, copier);
        // TODO Auto-generated constructor stub
    }

    /*
     * @see net.phenix.comp.util.beancopier.AbstractPropertyCopier#couldSmartCopy(java.lang.Class)
     */
    @Override
    public boolean couldSmartCopy(Class<?> propertyType) {
        return true;
    }

    /*
     * @see net.phenix.comp.util.beancopier.AbstractPropertyCopier#smartCopyProperty(java.lang.Object, java.lang.String, java.lang.Class, java.lang.Object)
     */
    @Override
    public void smartCopyProperty(Object dest, String propertyName, Class<?> propertyType, Object value)
            throws Exception {
        if (PropertyUtils.isWriteable(dest, propertyName)) {
            BeanUtils.copyProperty(dest, propertyName, value);
        }
    }

}
